package com.itcodai.service.impl;

import com.itcodai.dao.role.RoleMapper;
import com.itcodai.dbconnect.annotation.Master;
import com.itcodai.dbconnect.annotation.Slaver;
import com.itcodai.entity.Role;
import com.itcodai.service.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author c-fanqj
 * @date 2023/3/27
 * @apiNote
 */
@Service
public class RoleServiceImpl implements RoleService {

    private static final Logger logger
            = LoggerFactory.getLogger(RoleServiceImpl.class);

    @Resource
    private RoleMapper roleMapper;

    @Override
    public Role getRole(Long id) {
        Role role = new Role();
        role.setId(id);
        return roleMapper.selectByPrimaryKey(role);
    }

    @Slaver
    @Override
    public Role getAndInsertRole(Role role) {
        return roleMapper.selectByPrimaryKey(role);
        //return roleMapper.getRoleDetail(role.getId());
    }

    @Master
    @Override
    public Role insertRole(Role role) {
        //role.setCreated(null);
        roleMapper.insertUseGeneratedKeys(role);
        logger.info("插入成功，id： {} ， role:{}", role.getId(), role);
        return role;
    }


}
